from common.base import Base
from selenium.webdriver.common.by import By
from pages.login_page import LoginPage
from selenium import webdriver


class SelectPage(Base):
    scheduler_menu_loc = (By.CLASS_NAME, "el-submenu__title")
    database_menu_loc = (By.XPATH, "//li[@class='el-submenu is-opened']//li[1]")
    server_node_menu_loc = (By.XPATH, "//li[@class='el-submenu is-opened']//li[2]")
    step_manage_menu_loc = (By.XPATH, "//li[@class='el-submenu is-opened']//li[3]")
    step_group_manage_menu_loc = (By.XPATH, "//li[@class='el-submenu is-opened']//li[4]")
    task_manage_menu_loc = (By.XPATH, "//li[@class='el-submenu is-opened']//li[5]")
    task_history_menu_loc = (By.XPATH, "//li[@class='el-submenu is-opened']//li[6]")
    log_download_menu_loc = (By.XPATH, "//li[@class='el-submenu is-opened']//li[7]")
    redis_manage_menu_loc = (By.XPATH, "//li[@class='el-submenu is-opened']//li[8]")

    def click_scheduler_menu(self):
        # 点击调度中心菜单按钮
        self.click(self.scheduler_menu_loc)

    def click_database_menu(self):
        # 点击数据库管理菜单按钮
        self.click(self.database_menu_loc)

    def click_server_node_menu(self):
        # 点击服务器节点管理菜单按钮
        self.click(self.server_node_menu_loc)

    def click_step_manage(self):
        # 点击步骤管理菜单按钮
        self.click(self.step_manage_menu_loc)

    def click_stepgroup_manage(self):
        # 点击步骤组管理菜单按钮
        self.click(self.step_group_manage_menu_loc)

    def click_task_manage(self):
        # 点击任务管理菜单按钮
        self.click(self.task_manage_menu_loc)

    def click_task_history(self):
        # 点击任务历史信息菜单按钮
        self.click(self.task_history_menu_loc)

    def click_log_download(self):
        # 点击运维日志下载菜单按钮
        self.click(self.log_download_menu_loc)

    def click_redis_manage(self):
        # 点击redis运维管理菜单按钮
        self.click(self.redis_manage_menu_loc)


if __name__ == '__main__':
    driver = webdriver.Chrome()
    driver.get('http://172.28.30.2:9000/platform/#/login')
    driver.maximize_window()
    l = LoginPage(driver)
    l.login('admin', '111111-a')
    text = l.get_wel_username()
    if text == "超级管理员":
        print('登录成功')
    driver.quit()
